package com.time.client.application.converter;

import com.time.client.application.dto.PostDTO;
import com.time.client.common.entity.PageResult;
import com.time.client.domain.entity.PostBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 文章DTO转换类
 *
 * @author: HuangQi
 * @date: Created in 9:57 2025/11/4
 * @description: 文章DTO转换类
 */
@Mapper
public interface PostDTOConverter {

    PostDTOConverter INSTANCE = Mappers.getMapper(PostDTOConverter.class);

    PostBO convertDTOToBO(PostDTO postDTO);

    List<PostDTO> convertBOListToDTO(List<PostBO> tagBOList);

    PostDTO convertBOToDTO(PostBO postBO);

    default PageResult<PostDTO> convertBOPageToDTOPage(PageResult<PostBO> boPage) {
        PageResult<PostDTO> dtoPage = new PageResult<>();
        if (boPage == null) {
            return dtoPage;
        }
        dtoPage.setPageNo(boPage.getPageNo());
        dtoPage.setPageSize(boPage.getPageSize());
        dtoPage.setTotal(boPage.getTotal());
        dtoPage.setTotalPage(boPage.getTotalPage());
        dtoPage.setStart(boPage.getStart());
        dtoPage.setEnd(boPage.getEnd());
        if (boPage.getResult() != null && !boPage.getResult().isEmpty()) {
            List<PostDTO> dtoList = convertBOListToDTO(boPage.getResult());
            dtoPage.setResult(dtoList);
        }
        return dtoPage;
    }
}
